import { outArea, inArea } from "./utils.js"

export const positionData = [ 
  // 人头规则测试
  // E violate
  /*
  {dev_id: "0001D", x: 52, y: 8, intvl: 3000},
  {dev_id: "0001E", x: 56, y: 7, intvl: 3000},
  {dev_id: "0001F", x: 59, y: 9, intvl: 3000},  // F Violate
  {dev_id: "0001G", x: 42 , y: 8, intvl: 1000}, // E Clear
  {dev_id: "0001G", x: 11, y: 5, intvl: 2000},  // E violate
  {dev_id: "0001D", x: 44, y: 5, intvl: 2000},  // E clear and F clear
  */
  // E violete
  {dev_id: "0001D", x: 52, y: 8, intvl: 3000},
  {dev_id: "0001E", x: 56, y: 7, intvl: 3000},
  {dev_id: "0001G", x: 42 , y: 8, intvl: 1000},
  {dev_id: "0001G", x: 45 , y: 2, intvl: 1000}, // E clear
  {dev_id: "0001H", x: 43 , y: 5, intvl: 1000},
  {dev_id: "0001G", x: 4 , y: 8, intvl: 1000},  // E violate
  {dev_id: "0001G", x: 43, y: 9, intvl: 1000},  // E clear A Voilate



/*
  // 禁出/入测试
  {dev_id: "0001D", x: 12, y: 5}, // B Violate E Violate
  {dev_id: "0001D", x: 42, y: 5}, // B clear E Clear
  {dev_id: "0001D", x: 12, y: 5}, // B violate E Violate
  {dev_id: "0001H", x:  5, y: 5},
  {dev_id: "0001H", x: 66, y: 5}, // A violate
  {dev_id: "0001I", x:  5, y: 5}, 
  {dev_id: "0001H", x: 5, y: 5}, // A clear
  {dev_id: "0001H", x: 66, y: 5}, // A violate
  {dev_id: "0001I", x: 66, y: 5}, // A violate
  {dev_id: "0001I", x: 5, y: 5}, // A clear

  // 禁出入带计时器测试 
  {dev_id: "0001J", x: 25, y: 6}, 
  {dev_id: "0001J", x: 63, y: 5}, // C violate
  {dev_id: "0001J", x: 25, y: 6}, // C clear 
  {dev_id: "0001J", x: 63, y: 5}, // C violate
  {dev_id: "0001J", x: 25, y: 6}, // C clear 

  // 禁出入混合计时器测试
  {dev_id: "0001K", x: 15, y: 6}, // B Violate
  {dev_id: "0001K", x: 5, y: 6},  // B Clear 但进了A
  {dev_id: "0001K", x: 35, y: 6}, // 出A进D  A Violate
  {dev_id: "0001K", x: 21, y: 6}, // C no violate 

  // 区域暂停测试
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 67, y: 6},
  {dev_id: "0001M", x: 67, y: 6},
  {dev_id: "0001M", x: 67, y: 6},
  {dev_id: "0001M", x: 66, y: 6},

  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 66, y: 6},
  {dev_id: "0001M", x: 67, y: 6},
*/
]

export const zoneGeoms = 
  {"A": [{x: 0, y: 0}, {x: 10, y: 0}, {x: 10, y: 10}, {x:0, y: 10}, {x:0, y:0}],
   "B": [{x: 11, y: 0}, {x: 20, y: 0}, {x: 20, y: 10}, {x:11, y:10}, {x: 11, y: 0}],
   "C": [{x: 21, y: 0}, {x: 30, y: 0}, {x: 30, y: 10}, {x:21, y: 10}, {x: 21, y:0}],
   "D": [{x: 31, y: 0}, {x: 40, y: 0}, {x: 40, y: 10}, {x: 31, y:10}, {x: 31, y: 0}],
   "E": [{x:41, y: 0}, {x: 50, y: 0}, {x:50, y:10}, {x:41, y:10}, {x:41, y:0}],
   "F": [{x:51, y: 0}, {x: 60, y: 0}, {x:60, y: 10}, {x: 51, y:10}, {x:51, y:0}],
   "G": [{x: 61, y:0}, {x: 70, y:0}, {x: 70, y: 10}, {x: 61, y:10}, {x: 61, y:0}]
  }


export const rules = [
  { name: "keep_in",
    check_on: "tko",
    checkFn: outArea,
    zoneId: "A",
    tkos: [],
    excludeObjs: [],
    // 默认为零, 延迟多久激发
    timeout: 0
  },
  { name: "keep_out",
    check_on: "tko",
    checkFn: inArea,
    zoneId: "B",
    tkos: [],
    excludeTkos: [],
    timeout: 0
  },
  { name: "keep_in",
    check_on: "tko",
    checkFn: outArea, 
    zoneId: "C",
    tkos: ["0000abc"],
    excludeTkos: [],
    timeout: 500 
  },
  { name: "keep_out",
    check_on: "tko",
    checkFn: inArea,
    zoneId: "D",
    tkos: ["0000abc"],
    excludeTkos: [],
    timeout: 500
  },
  { name: "in_area_count_least",
    check_on: "zone",
    checkFn: inArea, 
    zoneId: "E",
    countLeast: 2,
  },
  { name: "in_area_count_max",
    check_on: "zone",
    checkFn: inArea, 
    zoneId: "F",
    countMax: 2,
  },
  {
    name: "in_area_pause_limit",
    check_on: "tko",
    checkFn: inArea,
    zoneId: "G",
    tkos: ["0000abc"],
    excludeTkos: [],
    timeout: 3000
  }
]

// Todo: must have a rules factory which checks the 
// rule name be one of the follwing parameters
const zone_rules = ["in_area_count_least", "in_area_count_max"]
const tko_rules  = ["keep_in", "keep_out", "in_area_pause_limit"]

// when expression() === true violated else cleared
// 